package com.rinoiot.weather.entity;

import com.rinoiot.weather.entity.Vo.CurrentWeatherVo;
import lombok.Data;

import java.util.List;

/**
 * WeatherBit返回天气数据实体类
 */
@Data
public class WeatherBitEntity {

    private List<WeatherBitData> data;

    private Integer count;

    @Data
    public static class WeatherBitData {

        /* 缩写风向 */
        private String wind_cdir;

        /* 相对湿度 (%) */
        private Integer rh;

        /*  */
        private String pod;

        /*  */
        private Double lon;

        /*  */
        private Integer pres;

        /*  */
        private String timezone;

        /*  */
        private String ob_time;

        /*  */
        private String country_code;

        /*  */
        private Integer clouds;

        /*  */
        private Long ts;

        /*  */
        private Integer solar_rad;

        /*  */
        private String state_code;

        /*  */
        private String city_name;

        /*  */
        private Double wind_spd;

        /*  */
        private Double slp;

        /*  */
        private String wind_cdir_full;

        /*  */
        private String sunrise;

        /*  */
        private Double app_temp;

        /*  */
        private Integer dni;

        /*  */
        private Integer vis;

        /*  */
        private List<String> sources;

        /*  */
        private Integer h_angle;

        /*  */
        private Double dewpt;

        /*  */
        private Integer snow;

        /*  */
        private Integer aqi;

        /*  */
        private Integer dhi;

        /*  */
        private Integer wind_dir;

        /*  */
        private Double elev_angle;

        /*  */
        private Integer ghi;

        /*  */
        private Integer precip;

        /*  */
        private String sunset;

        /*  */
        private Double lat;

        /*  */
        private Integer uv;

        /*  */
        private String datetime;

        /*  */
        private Double temp;

        /*  */
        private Weather weather;

        /* [已弃用] 最近的报告站 ID */
        private String station;

    }

    @Data
    public static class Weather {
        private String icon;
        private Integer code;
        private String description;
    }

    public CurrentWeatherVo trans() {
        CurrentWeatherVo vo = new CurrentWeatherVo();
        vo.setCreateTime(System.currentTimeMillis());
        vo.setDescription(this.data.get(0).getWeather().getDescription());
        vo.setCityName(this.getData().get(0).getCity_name());
        vo.setLat(this.getData().get(0).getLat());
        vo.setLon(this.getData().get(0).getLon());

        vo.setTemp(String.valueOf(this.getData().get(0).getTemp()));
        vo.setRealFeel(String.valueOf(this.getData().get(0).getApp_temp()));
        vo.setHumidity(String.valueOf(this.getData().get(0).getRh()));
        vo.setPressure(String.valueOf(this.getData().get(0).getPres()));
        vo.setVis(String.valueOf(this.getData().get(0).getVis()));
        vo.setWindDir(this.getData().get(0).getWind_cdir_full());
        vo.setWindSpeed(String.valueOf(this.getData().get(0).getWind_spd()));
        vo.setApi(String.valueOf(this.getData().get(0).getAqi()));
        vo.setSunRise(this.getData().get(0).getSunrise());
        vo.setSunSet(this.getData().get(0).getSunset());

        return vo;
    }
}
